package com.zc.cityman.handler;

import com.zc.cityman.pojo.User;
import com.zc.cityman.service.impl.UserServiceimpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserHandler {
    @Resource
    UserServiceimpl userServiceimpl;
    @RequestMapping("login")
    @ResponseBody
    public String login(String account, String password, HttpServletRequest httpServletRequest
                        ){
        httpServletRequest.getSession().setAttribute("account",account);
        User login = userServiceimpl.login(account, password);

        if (login!=null){
            return "Y";
        }else{
            return "N";
        }


    }
    @RequestMapping("search")
    @ResponseBody
    public User search(@RequestParam("account") String account){
        User search = userServiceimpl.search(account);
        System.out.println(search);
        return search;
    }


    @RequestMapping("regist")
    @ResponseBody
    public String regist(@RequestBody User user){
        Integer regist = userServiceimpl.regist(user);
        System.out.println(regist);
        return regist==1?"Y":"N";
    }



}
